home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
IRIX 6.5 Applications 1999 May
/
SGI IRIX 6.5 Applications 1999 May.iso
/
dist
/
insight.idb
/
usr
/
share
/
Insight
/
xhelp
/
samples
/
exampleApp
/
exampleAppXm.c.z
/
exampleAppXm.c
Wrap
C/C++ Source or Header
|
1998-05-04
|
13KB
|
480 lines
/*_____________________________________________________________________________
*
* File: exampleAppXm.c
*
* Date: 3/25/94
*
* Compile with: cc -o exampleAppXm exampleAppXm.c -lhelpmsg -lXm -lXt -lX11
*
* Purpose: An simple example program that shows how to use the SGI
* Help system from a Motif application.
*
* This program displays a few buttons on a bulletin board
* alongwith a help menu. The use of context sensitive help
* is also demonstrated.
*_____________________________________________________________________________
*/
/*
* standard include files
*/
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <X11/cursorfont.h>
#include <Xm/Xm.h>
#include <Xm/Label.h>
#include <Xm/PushB.h>
#include <Xm/Form.h>
#include <Xm/MessageB.h>
#include <Xm/MainW.h>
#include <Xm/RowColumn.h>
#include <Xm/CascadeB.h>
#include <Xm/Separator.h>
/*
* include for for calling/using SGIHelp
*/
#include <helpapi/HelpBroker.h>
/*
* forward declarations of functions
*/
Widget initMotif(int *argcP, /* Initializes motif and */
char *argv[], /* and returns the top level*/
XtAppContext *app_contextP, /* shell. */
Display **displayP);
void createInterface(Widget parent); /*creates the main window, */
/*menus, and the buttons */
/*on the main window */
void clickForHelpCB(); /*callbacks for each of */
void overviewCB(); /*the help menu's */
void taskCB();
void indexCB();
void keysAndShortcutsCB();
void productInfoCB();
void infoDialogCB();
Widget _mainWindow, _infoDialog=NULL;
/*_____________________________________________________________________________
*
* main()
*_____________________________________________________________________________
*/
main(int argc, char *argv[])
{
Display *display;
XtAppContext app_context;
Widget toplevel;
toplevel = initMotif (&argc,argv,&app_context,&display);
createInterface(toplevel);
XtRealizeWidget(toplevel);
XtAppMainLoop(app_context);
}
/*_____________________________________________________________________________
*
* Function: initMotif()
*
* Purpose: Initializes Motif and creates a top level shell.
* Returns the toplevel shell.
*
* Makes the call to initialize variables for the SGIHelp
* interface...note that it does not *start* the sgihelp
* process. That is done when a request for help is made,
* if and only if the sgihelp process is not already
* running.
*
*_____________________________________________________________________________
*/
Widget initMotif(int *argcP,char *argv[],XtAppContext *app_contextP,
Display **displayP)
{
Widget toplevel;
XtToolkitInitialize();
*app_contextP = XtCreateApplicationContext();
*displayP = XtOpenDisplay(*app_contextP,NULL,"exampleAppXm",
"exampleAppXmClass",NULL,
0,argcP, argv);
if (*displayP == NULL) {
fprintf (stderr,"Could not open display.\n");
fprintf (stderr,"Check your DISPLAY environment variable.\n");
fprintf (stderr,"Exiting...\n");
exit(-1);
}
toplevel = XtAppCreateShell("exampleAppXm", NULL,
applicationShellWidgetClass,
*displayP, NULL,0);
/*
* initialize variables for SGIHelp
*/
SGIHelpInit(*displayP, "exampleAppXm", ".");
return (toplevel);
}
/*_____________________________________________________________________________
*
* Function: createInterface()
*_____________________________________________________________________________
*/
void createInterface(Widget parent)
{
Arg args[10];
int i;
Widget baseForm;
Widget menuBar;
Widget demoLabel, demoButton;
Widget pulldown1,pulldown2, cascade1, cascade2;
Widget menuButtons[6]; /*we will create at max 6 buttons on a menu*/
XmString xmStr;
/*
* mainWindow is an XmMainWindow
* on which the whole interface is built
*/
i=0;
_mainWindow = XmCreateMainWindow(parent,"mainWindow",args,i);
XtManageChild(_mainWindow);
/*
* baseForm is the workArea for the
* mainWindow above.
*/
i=0;
XtSetArg (args[i],XmNwidth,400);i++;
XtSetArg (args[i],XmNheight,300);i++;
XtSetArg (args[i],XmNverticalSpacing,40);i++;
baseForm = XmCreateForm(_mainWindow,"baseForm",args,i);
XtManageChild(baseForm);
/*
* On this bulletin board, put a label and a button
* for demonstrating callbacks and context sensitive
* help.
*/
i=0;
xmStr = XmStringCreateSimple("SGI Help!");
XtSetArg (args[i],XmNlabelString,xmStr);i++;
XtSetArg (args[i],XmNtopAttachment,XmATTACH_FORM);i++;
XtSetArg (args[i],XmNrightAttachment,XmATTACH_FORM);i++;
XtSetArg (args[i],XmNleftAttachment,XmATTACH_FORM);i++;
XtSetArg (args[i],XmNalignment,XmALIGNMENT_CENTER);i++;
demoLabel = XmCreateLabel(baseForm,"sgiHelpLabel",args,i);
XtManageChild(demoLabel);
XmStringFree(xmStr);
i=0;
xmStr = XmStringCreateSimple("Click Here For Help");
XtSetArg (args[i],XmNlabelString,xmStr);i++;
XtSetArg (args[i],XmNrightAttachment,XmATTACH_FORM);i++;
XtSetArg (args[i],XmNbottomAttachment,XmATTACH_FORM);i++;
demoButton = XmCreatePushButton(baseForm,"sgiHelpPushButton",args,i);
XtManageChild(demoButton);
XmStringFree(xmStr);
XtAddCallback(demoButton,XmNactivateCallback,taskCB,NULL);
/*
* build a pulldown menu system, including the "help" menu
*/
menuBar = XmCreateMenuBar(_mainWindow,"menuBar",NULL,0);
XtManageChild(menuBar);
pulldown1 = XmCreatePulldownMenu(menuBar,"pulldown1",NULL,0);
pulldown2 = XmCreatePulldownMenu(menuBar,"pulldown2",NULL,0);
i=0;
XtSetArg (args[i],XmNsubMenuId,pulldown1);i++;
cascade1 = XmCreateCascadeButton(menuBar,"File",args,i);
XtManageChild(cascade1);
i=0;
XtSetArg (args[i],XmNsubMenuId,pulldown2);i++;
cascade2 = XmCreateCascadeButton(menuBar,"Help",args,i);
XtManageChild(cascade2);
/*
* Declare this to be the Help menu
*/
i=0;
XtSetArg (args[i],XmNmenuHelpWidget,cascade2);i++;
XtSetValues(menuBar,args,i);
menuButtons[0] = XmCreatePushButton(pulldown1,"Exit",NULL,0);
XtManageChildren(menuButtons,1);
XtAddCallback(menuButtons[0],XmNactivateCallback,(XtCallbackProc)exit,0);
menuButtons[0] = XmCreatePushButton(pulldown2,"Click for Help",NULL,0);
menuButtons[1] = XmCreatePushButton(pulldown2,"Overview",NULL,0);
XtManageChild( XmCreateSeparator(pulldown2, "separator1",NULL,0) );
menuButtons[2] = XmCreatePushButton(pulldown2,"Sample Help Task",NULL,0);
XtManageChild( XmCreateSeparator(pulldown2, "separator2",NULL,0) );
menuButtons[3] = XmCreatePushButton(pulldown2,"Index",NULL,0);
menuButtons[4] = XmCreatePushButton(pulldown2,"Keys and Shortcuts",NULL,0);
XtManageChild( XmCreateSeparator(pulldown2, "separator3",NULL,0) );
menuButtons[5] = XmCreatePushButton(pulldown2,"Product Information",NULL,0);
XtManageChildren(menuButtons,6);
/*
* add callbacks to each of the help menu buttons
*/
XtAddCallback(menuButtons[0],XmNactivateCallback,clickForHelpCB,NULL);
XtAddCallback(menuButtons[1],XmNactivateCallback,overviewCB,NULL);
XtAddCallback(menuButtons[2],XmNactivateCallback,taskCB,NULL);
XtAddCallback(menuButtons[3],XmNactivateCallback,indexCB,NULL);
XtAddCallback(menuButtons[4],XmNactivateCallback,keysAndShortcutsCB,NULL);
XtAddCallback(menuButtons[5],XmNactivateCallback,productInfoCB,NULL);
/*
* set the bulletin board and menubar into
* the main Window.
*/
XmMainWindowSetAreas(_mainWindow,menuBar,NULL,NULL,NULL,baseForm);
}
/*_____________________________________________________________________________
*
* void clickForHelpCB()
*
* Purpose: Provides context-sensitivity within an application;
* makes a request to the sgihelp process.
*
*_____________________________________________________________________________
*/
void clickForHelpCB(Widget wid, XtPointer clientData, XtPointer callData)
{
static Cursor cursor = NULL;
static char path[512], tmp[512];
Widget shell, result, w;
strcpy(path, "");
strcpy(tmp, "");
/*
* create a question-mark cursor
*/
if(!cursor)
cursor = XCreateFontCursor(XtDisplay(wid), XC_question_arrow);
XmUpdateDisplay(_mainWindow);
/*
* get the top-level shell for the window
*/
shell = _mainWindow;
while (shell && !XtIsShell(shell)) {
shell = XtParent(shell);
}
/*
* modal interface for selection of a component;
* returns the widget or gadget that contains the pointer
*/
result = XmTrackingLocate(shell, cursor, FALSE);
if( result ) {
w = result;
/*
* get the widget hierarchy; separate with a '.';
* this also puts them in top-down vs. bottom-up order.
*/
do {
if( XtName(w) ) {
strcpy(path, XtName(w));
if( strlen(tmp) > 0 ) {
strcat(path, ".");
strcat(path, tmp);
}
strcpy(tmp, path);
}
w = XtParent(w);
} while (w != NULL && w != shell);
/*
* send msg to the help server-widget hierarchy;
* OR
* provide a mapping to produce the key to be used
*
* In this case, we'll let the sgihelp process do
* the mapping for us, with the use of a helpmap file
*
* Note that parameter 2, the book name, can be found
* from the helpmap file as well. The developer need
* not hard-code it, if a helpmap file is present for
* the application.
*
*/
if( strlen(path) > 0 ) {
SGIHelpMsg(path, NULL, NULL);
}
}
}
/*_____________________________________________________________________________
*
* void overviewCB()
*_____________________________________________________________________________
*/
void overviewCB()
{
/*
* Using the mapping file allows us to specify
* a "Overview" help card for each window in
* our application. In this case, we will point
* to a specific one. Note that the book name is
* specified, but not necessary if a helpmap file
* exists for this application.
*/
SGIHelpMsg("overview", "exampleAppXmHelp", NULL);
}
/*_____________________________________________________________________________
*
* void indexCB()
*_____________________________________________________________________________
*/
void indexCB()
{
/*
* For the index window to work for this application,
* a helpmap file MUST be present!
*/
SGIHelpIndexMsg("index", NULL);
}
/*_____________________________________________________________________________
*
* void taskCB()
*_____________________________________________________________________________
*/
void taskCB()
{
/*
* For the task found in the help menu or a pushbutton, we
* use a specific key/book combination.
*/
SGIHelpMsg("help_task", "exampleAppXmHelp", NULL);
}
/*_____________________________________________________________________________
*
* void keysAndShortcutsCB()
*_____________________________________________________________________________
*/
void keysAndShortcutsCB()
{
/*
* This would point to the help card that contains
* information about the use of keys/accelerators, etc.
* for your application.
*/
SGIHelpMsg("keys", "exampleAppXmHelp", NULL);
}
/*_____________________________________________________________________________
*
* void productInfoCB()
*_____________________________________________________________________________
*/
void productInfoCB()
{
/*
* Pops up a dialog showing product version information.
*
* This area has nothing to do with SGIHelp, but is included
* for completeness.
*/
void buildInfoDialog();
XmString xmStr;
Arg args[10];
int i;
if( _infoDialog == NULL ) {
buildInfoDialog();
XtRealizeWidget( _infoDialog );
}
xmStr=XmStringCreateSimple("Example Motif App Using SGIHelp version 1.0");
i=0;
XtSetArg (args[i],XmNmessageString,xmStr);i++;
XtSetValues(_infoDialog, args, i);
XmStringFree(xmStr);
XtManageChild(_infoDialog);
}
void buildInfoDialog()
{
Arg args[10];
int i;
/*
* Build the informational dialog to display the version info
*/
i=0;
XtSetArg (args[i],XmNautoUnmanage,True);i++;
XtSetArg (args[i],XmNdialogType,XmDIALOG_WORKING);i++;
XtSetArg (args[i],XmNdialogStyle,XmDIALOG_APPLICATION_MODAL);i++;
_infoDialog = XmCreateInformationDialog(_mainWindow,"infoDialog",args,i);
XtAddCallback(_infoDialog, XmNokCallback, infoDialogCB, NULL);
XtUnmanageChild(XmMessageBoxGetChild(_infoDialog, XmDIALOG_CANCEL_BUTTON));
XtUnmanageChild(XmMessageBoxGetChild(_infoDialog, XmDIALOG_HELP_BUTTON));
}
void infoDialogCB()
{
if ( _infoDialog ) {
XtUnmanageChild(_infoDialog);
/* Explicitly set the input focus */
XSetInputFocus(XtDisplay(_mainWindow), PointerRoot,
RevertToParent, CurrentTime);
}
}